package com.jushu.storbox.newfragment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jushu.storbox.AlbumSelectActivity;
import com.jushu.storbox.R;
import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.adapter.AbsTemplateAdapter;
import com.jushu.storbox.callback.ITCallback;
import com.jushu.storbox.constant.Constant;
import com.jushu.storbox.constant.ReceiverConstent;
import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.database.DAOFactory;
import com.jushu.storbox.database.IUserDao;
import com.jushu.storbox.entities.AlbumFileInfo;
import com.jushu.storbox.entities.UploadObject;
import com.jushu.storbox.entities.User;
import com.jushu.storbox.handler.ClientExceptionRelateHandler;
import com.jushu.storbox.manager.AlbumBackManager;
import com.jushu.storbox.manager.AlbumUploadTaskManager;
import com.jushu.storbox.util.LogUtil;
import com.jushu.storbox.util.PublicTools;
import com.jushu.storbox.util.image.BitmapUtil;
import com.jushu.storbox.view.dialog.AbsPopupMenuDialog;
import com.jushu.storbox.view.viewImpl.SlipButton;
import com.jushu.storbox.view.viewImpl.SlipButton.OnChangedListener;
import com.huawei.sharedrive.sdk.android.modelV2.response.FileInfoResponseV2;
import com.huawei.sharedrive.sdk.android.util.StringUtil;

public class AlbumBackFragment extends AbsFrameFragment {

	public final static String TAG = AlbumBackFragment.class.getSimpleName();

	public final static String CURRENT_ITEM_PROCED_SIZE = "CURRENT_ITEM_PROCED_SIZE";

	public final static int WIDTH = 200;
	public final static int HEIGHT = 170;

	/** finished layer */
	View albumLayer1;

	/** progress layer */
	View albumLayer2;

	Button enableBtn;
	View album_backup_setting;
	View backupProgressPromit;
	ImageView current_backup_item;
	ProgressBar backupProgress;
	private TextView resultDeteil2;
	private TextView backupStop;

	@SuppressWarnings("unused")
	private View backupStatus;

	private TextView resultDeteil1;
	private SlipButton albumAutoBackBtn;
	private SlipButton albumWifiOnlyBtn;
	private View albumCatchSetting;
	private User currentUser = null;

	private long totalAlbumSize = 0;
	private long backupedSize = 0;
	private int progress;

	AbsPopupMenuDialog dialog;
	List<AlbumFileInfo> albumFailList = new ArrayList<AlbumFileInfo>();
	AlbumBackupFailureAdapter adapter = new AlbumBackupFailureAdapter(albumFailList);
	private ListView listView;
	private TextView failureTitle;

	Bitmap currentProcBitmap = null;

	TaskBroadcastReceiver reciver = new TaskBroadcastReceiver();

	@Override
	protected int getTitleResourceId() {
		return R.layout.action_title_simple;
	}

	@Override
	protected int getContentResourceId() {
		return R.layout.activity_album_backup;
	}

	@Override
	protected void startInitConpentData() {
	}

	@Override
	protected void onLoadTitleView(View titleView) {
		super.onLoadTitleView(titleView);
		TextView fragmentTitleName = (TextView) titleView.findViewById(R.id.fragmentTitleName);
		fragmentTitleName.setText(R.string.album_backup);
	}

	@Override
	protected void onLoadContentView(View contentView) {
		super.onLoadContentView(contentView);
		// initlayer
		albumLayer1 = contentView.findViewById(R.id.album_layer_1);
		enableBtn = (Button) contentView.findViewById(R.id.albumBackupEnable);
		backupProgressPromit = contentView.findViewById(R.id.album_backup_result_promit);
		backupStatus = contentView.findViewById(R.id.album_backup_status);
		resultDeteil1 = (TextView) contentView.findViewById(R.id.album_backup_result_deteil1);
		// backuplayer
		albumLayer2 = contentView.findViewById(R.id.album_layer_2);
		current_backup_item = (ImageView) contentView.findViewById(R.id.current_backup_item);
		backupProgress = (ProgressBar) contentView.findViewById(R.id.album_backup_progress);
		resultDeteil2 = (TextView) contentView.findViewById(R.id.album_backup_result_deteil2);
		backupStop = (TextView) contentView.findViewById(R.id.album_backup_stop);
		// settinglayer
		album_backup_setting = contentView.findViewById(R.id.album_backup_setting);
		albumAutoBackBtn = (SlipButton) contentView.findViewById(R.id.albumAutoBackBtn);
		albumWifiOnlyBtn = (SlipButton) contentView.findViewById(R.id.albumWifiOnlyBtn);
		albumCatchSetting = contentView.findViewById(R.id.album_catch_setting);

		dialog = new AbsPopupMenuDialog(getActivity(), R.style.dialog_upload, R.layout.adapter_view_album_backup_failure_item) {

			@Override
			public void onInflaterFinished(View contentView) {
				failureTitle = (TextView) contentView.findViewById(R.id.album_backup_failure_title);
				listView = (ListView) contentView.findViewById(R.id.album_backup_failure_list);

				View cancelButton = contentView.findViewById(R.id.dialog_add_file_cancal_bt);
				View okButton = contentView.findViewById(R.id.dialog_add_file_ok_bt);

				cancelButton.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						dismiss();
					}
				});
				okButton.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						dismiss();
					}
				});
			}

		};

		backupProgress.setMax(100);
		// init view
		albumLayer1.setVisibility(View.VISIBLE);
		albumLayer2.setVisibility(View.INVISIBLE);

		String formatStr = getActivity().getString(R.string.album_back_remain_str);
		resultDeteil2.setText(String.format(formatStr, 0));

		currentUser = ShareDriveApplication.getInstance().getCurrentUser();
		if (currentUser != null) {
			switch (currentUser.getAlbumAutoBackup()) {
			case IUserDao.ALBUM_AUTO_BACKUP_FALSE:
				albumAutoBackBtn.setCheck(false);
				break;
			case IUserDao.ALBUM_AUTO_BACKUP_TRUE:
				albumAutoBackBtn.setCheck(true);
				break;
			}

			switch (currentUser.getBackupAlbumOnlyWifi()) {
			case IUserDao.ALBUM_BACKUP_ONLYWIFI_FALSE:
				albumWifiOnlyBtn.setCheck(false);
				break;
			case IUserDao.ALBUM_BACKUP_ONLYWIFI_TRUE:
				albumWifiOnlyBtn.setCheck(true);
				break;
			}

			if (currentUser.getAlbumEnabled() == IUserDao.ALBUM_ENABLED_TRUE) {
				backupProgressPromit.setVisibility(View.VISIBLE);
				// show the setting layer
				showCurrentUiAndData();
			} else {
				enableBtn.setVisibility(View.VISIBLE);
				backupProgressPromit.setVisibility(View.INVISIBLE);
				// hide the setting layer
				album_backup_setting.setVisibility(View.INVISIBLE);
			}

			switch (currentUser.getBackupStoped()) {
			case IUserDao.ALBUM_BACKUP_STOPED_FALSE:
				backupStop.setText(R.string.album_backup_stop_str);
				break;
			case IUserDao.ALBUM_BACKUP_STOPED_TRUE:
				backupStop.setText(R.string.album_backup_contine_str);
				break;
			}

		} else {
			albumAutoBackBtn.setCheck(false);
			enableBtn.setVisibility(View.VISIBLE);
			backupProgressPromit.setVisibility(View.INVISIBLE);
			// hide the setting layer
			album_backup_setting.setVisibility(View.INVISIBLE);
		}

		// init listener
		enableBtn.setOnClickListener(firstEnableBackupListener);
		albumAutoBackBtn.SetOnChangedListener(new OnChangedListener() {
			public void OnChanged(boolean CheckState) {
				currentUser = ShareDriveApplication.getInstance().getCurrentUser();
				if (!CheckState) {
					if (currentUser != null) {
						AlbumBackManager.instance(getActivity()).stopAlbumBackup();
						// force clear all saved data
						DAOFactory.instance(getActivity()).getAlbumDao().updateAlbumStateToNew();
						currentUser.setAlbumAutoBackup(IUserDao.ALBUM_AUTO_BACKUP_FALSE);
						DAOFactory.instance(getActivity()).getUserDao().updateAlbumBackFlag(currentUser);
					}
					totalAlbumSize = 0;
					backupedSize = 0;
					progress = 0;
				} else {
					if (currentUser != null) {
						currentUser.setAlbumAutoBackup(IUserDao.ALBUM_AUTO_BACKUP_TRUE);
						DAOFactory.instance(getActivity()).getUserDao().updateAlbumBackFlag(currentUser);
						AlbumUploadTaskManager.instance().startTaskExecuteService();
						AlbumBackManager.instance(getActivity()).startAlbumBackup();
					}
				}
			}
		});
		albumWifiOnlyBtn.SetOnChangedListener(new OnChangedListener() {
			public void OnChanged(boolean CheckState) {
				currentUser = ShareDriveApplication.getInstance().getCurrentUser();
				if (currentUser != null) {
					if (CheckState) {
						currentUser.setBackupAlbumOnlyWifi(IUserDao.ALBUM_BACKUP_ONLYWIFI_TRUE);
					} else {
						currentUser.setBackupAlbumOnlyWifi(IUserDao.ALBUM_BACKUP_ONLYWIFI_FALSE);
					}
					DAOFactory.instance(getActivity()).getUserDao().updateWifiConfig(currentUser);
				}
			}
		});
		resultDeteil1.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				dialog.show();
				String strFormat = String.format(getActivity().getString(R.string.failure_count), albumFailList.size());
				failureTitle.setText(strFormat);
				listView.setAdapter(adapter);
			}
		});

		albumCatchSetting.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent intent = new Intent(getMainFrameActivity(), AlbumSelectActivity.class);
				startActivityForResult(intent, UiConstant.SETTING_ALBUM_ACTIVITY_REQUEST_CODE);
			}
		});

		backupStop.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				switch (currentUser.getBackupStoped()) {
				case IUserDao.ALBUM_BACKUP_STOPED_FALSE:
					backupStop.setText(R.string.album_backup_contine_str);
					currentUser.setBackupStoped(IUserDao.ALBUM_BACKUP_STOPED_TRUE);
					DAOFactory.instance(getActivity()).getUserDao().updateBackStopFlag(currentUser);
					AlbumBackManager.instance(getActivity()).stopAlbumBackup();
					break;

				case IUserDao.ALBUM_BACKUP_STOPED_TRUE:
					backupStop.setText(R.string.album_backup_stop_str);
					currentUser.setBackupStoped(IUserDao.ALBUM_BACKUP_STOPED_FALSE);
					DAOFactory.instance(getActivity()).getUserDao().updateBackStopFlag(currentUser);
					AlbumBackManager.instance(getActivity()).startAlbumBackup();
					break;
				}
			}
		});
	}

	public void showCurrentUiAndData() {
		enableBtn.setVisibility(View.INVISIBLE);
		album_backup_setting.setVisibility(View.VISIBLE);

		int remainCount = DAOFactory.instance(getActivity()).getAlbumDao().getRemainCount();
		Log.i("test", "remainCount = " + remainCount);
		if (remainCount != 0) {
			albumLayer1.setVisibility(View.INVISIBLE);
			String formatStr = getActivity().getString(R.string.album_back_remain_str);
			resultDeteil2.setText(String.format(formatStr, remainCount));
			AlbumUploadTaskManager.instance().registerCallback(iCallback);
			albumLayer2.setVisibility(View.VISIBLE);
		} else {
			albumLayer2.setVisibility(View.INVISIBLE);
			List<AlbumFileInfo> failureList = DAOFactory.instance(getActivity()).getAlbumDao().getFailedAlbumInfoList();
			adapter.resetDatas(failureList);
			String formatStr = getActivity().getString(R.string.album_backup_failure_promit);
			resultDeteil1.setText(String.format(formatStr, failureList.size()));
			albumLayer1.setVisibility(View.VISIBLE);
		}
	}

	OnClickListener firstEnableBackupListener = new OnClickListener() {
		public void onClick(View arg0) {
			Intent intent = new Intent(getMainFrameActivity(), AlbumSelectActivity.class);
			startActivityForResult(intent, UiConstant.SETTING_ALBUM_ACTIVITY_REQUEST_CODE);
		}
	};

	@Override
	public void onResume() {
		LogUtil.d(TAG, "register reciver");
		IntentFilter filter = new IntentFilter(ReceiverConstent.ALBUM_TASK_NEW_INSTANCE_ACTION);
		getActivity().registerReceiver(reciver, filter);
		initAlbumParams();
		backupProgress.setProgress(progress);
		backupProgress.setMax(100);
		super.onResume();
	}

	@Override
	public void onPause() {
		getActivity().unregisterReceiver(reciver);
		LogUtil.d(TAG, "unregister reciver");
		super.onPause();
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		LogUtil.i(TAG, "onActivityResult");
		Log.i(TAG, "req: " + requestCode + ", res: " + resultCode);
		if (requestCode == UiConstant.SETTING_ALBUM_ACTIVITY_REQUEST_CODE) {
			if (resultCode == UiConstant.SETTING_ALBUM_ACTIVITY_RETURN_CODE) {
				// albumLayer1.setVisibility(View.VISIBLE);
				// albumLayer2.setVisibility(View.INVISIBLE);
				// if(currentUser != null && currentUser.getAlbumEnabled() ==
				// IUserDao.ALBUM_ENABLED_TRUE) {
				// enableBtn.setVisibility(View.INVISIBLE);
				// backupProgressPromit.setVisibility(View.VISIBLE);
				// album_backup_setting.setVisibility(View.VISIBLE);
				// } else {
				// enableBtn.setVisibility(View.VISIBLE);
				// backupProgressPromit.setVisibility(View.INVISIBLE);
				// album_backup_setting.setVisibility(View.INVISIBLE);
				// }
			} else if (resultCode == UiConstant.SETTING_ALBUM_ACTIVITY_SAVE_CODE) {
				if (currentUser != null) {
					if (currentUser.getAlbumAutoBackup() == IUserDao.ALBUM_ENABLED_FALSE) {
						currentUser.setAlbumEnabled(IUserDao.ALBUM_ENABLED_TRUE);
						DAOFactory.instance(getActivity()).getUserDao().updateAlbumEnableFlag(currentUser);
						albumAutoBackBtn.setCheck(true);

						currentUser.setAlbumAutoBackup(IUserDao.ALBUM_AUTO_BACKUP_TRUE);
						DAOFactory.instance(getActivity()).getUserDao().updateAlbumBackFlag(currentUser);
						AlbumUploadTaskManager.instance().startTaskExecuteService();
						AlbumBackManager.instance(getActivity()).startAlbumBackup();
					}
				}
				// show the setting layer
				Log.i("test", "=======================================");
				showCurrentUiAndData();
			} else {
				// do nothing
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public void onStop() {
		AlbumUploadTaskManager.instance().unRegisterCallback(iCallback);
		super.onStop();
	}

	private void initAlbumParams() {
		int remainCount = DAOFactory.instance(getActivity()).getAlbumDao().getRemainCount();
		if (remainCount != 0) {
			String formatStr = getActivity().getString(R.string.album_back_remain_str);
			resultDeteil2.setText(String.format(formatStr, remainCount));
		} else {
			List<AlbumFileInfo> failureList = DAOFactory.instance(getActivity()).getAlbumDao().getFailedAlbumInfoList();
			adapter.resetDatas(failureList);
			String formatStr = getActivity().getString(R.string.album_backup_failure_promit);
			resultDeteil1.setText(String.format(formatStr, failureList.size()));
		}

		totalAlbumSize = DAOFactory.instance(getActivity()).getAlbumDao().getTotalAlbumSize();
		backupedSize = totalAlbumSize - DAOFactory.instance(getActivity()).getAlbumDao().getUnBackupedSize();
		computeCurrentProgress(0);
	}

	private int computeCurrentProgress(long currentSize) {
		double tempProgress;
		if (totalAlbumSize <= 0) {
			progress = 0;
		} else {
			tempProgress = (backupedSize + currentSize) * 1.0 / totalAlbumSize;
			progress = (int) (tempProgress * 100);
		}
		return progress;
	}

	private int getTypeImgeID(String fileName) {
		int typeImgResId = R.mipmap.default_file_icon;

		if (PublicTools.isFileType(fileName, Constant.WORD_TYPE)) {
			typeImgResId = R.mipmap.doc;
		} else if (PublicTools.isFileType(fileName, Constant.PPT_TYPE)) {
			typeImgResId = R.mipmap.ppt;
		} else if (PublicTools.isFileType(fileName, Constant.IMAGE_TYPE)) {
			typeImgResId = R.mipmap.empty_pic;
		} else if (PublicTools.isFileType(fileName, Constant.RAR_TYPE)) {
			typeImgResId = R.mipmap.rar;
		} else if (PublicTools.isFileType(fileName, Constant.ZIP_TYPE)) {
			typeImgResId = R.mipmap.rar;
		} else if (PublicTools.isFileType(fileName, Constant.VIDEO_TYPE)) {
			typeImgResId = R.mipmap.video;
		} else if (PublicTools.isFileType(fileName, Constant.MUSIC_TYPE)) {
			typeImgResId = R.mipmap.music;
		} else if (PublicTools.isFileType(fileName, Constant.TXT_TYPE)) {
			typeImgResId = R.mipmap.txt;
		} else if (PublicTools.isFileType(fileName, Constant.PDF_TYPE)) {
			typeImgResId = R.mipmap.pdf;
		} else if (PublicTools.isFileType(fileName, Constant.EXCEL_TYPE)) {
			typeImgResId = R.mipmap.excel;
		} else {
			typeImgResId = R.mipmap.default_file_icon;
		}

		return typeImgResId;
	}

	ClientExceptionRelateHandler handler = new ClientExceptionRelateHandler() {

		private String currentBackupPath = "";

		@Override
		public void handleMessage(Message msg) {

			if (!isResumed()) {
				return;
			}

			backupProgress.setProgress(progress);
			backupProgress.setMax(100);

			switch (msg.what) {
			case UiConstant.CALL_BACK_PREPERD:
				String madiePath = (String) msg.obj;
				handlePreperBackup(madiePath);
				break;

			case UiConstant.CALL_BACK_START:
				currentBackupPath = (String) msg.obj;
				handleBackupMadieStart(currentBackupPath);
				break;
			case UiConstant.CALL_BACK_PROCESS:
				Bundle bundle = msg.getData();
				long procedSize = bundle.getLong(CURRENT_ITEM_PROCED_SIZE);
				handleBackupMadieProc(procedSize);
				if (StringUtil.isBlank(currentBackupPath)) {
					currentBackupPath = (String) msg.obj;
					handleBackupMadieStart(currentBackupPath);
				}
				break;
			case UiConstant.CALL_BACK_SUCCESS:
				handleOneItemBackupFinished((String) msg.obj);
				currentBackupPath = "";
				break;
			case UiConstant.CALL_BACK_FIALURE:
				handleOneItemBackupFinished((String) msg.obj);
				currentBackupPath = "";
				break;
			default:
				super.handleMessage(msg);
			}

		}

		private void handlePreperBackup(String madiePath) {
			albumLayer1.setVisibility(View.INVISIBLE);
			albumLayer2.setVisibility(View.VISIBLE);
			File currentMadieFile = new File(madiePath);
			if (currentMadieFile.exists() && currentMadieFile.isFile()) {
				int resourceId = getTypeImgeID(currentMadieFile.getName());
				if (resourceId == R.mipmap.empty_pic) {
					Bitmap tempBitmap = currentProcBitmap;
					currentProcBitmap = BitmapUtil.decodeSampledBitmapFromFile(madiePath, WIDTH, HEIGHT);
					if (currentProcBitmap != null) {
						current_backup_item.setImageBitmap(currentProcBitmap);
					} else {
						current_backup_item.setImageResource(resourceId);
					}
					if (tempBitmap != null && !tempBitmap.isRecycled()) {
						tempBitmap.recycle();
						tempBitmap = null;
					}
				} else {
					current_backup_item.setImageResource(resourceId);
				}
			}
		}

		private void handleOneItemBackupFinished(String madiePath) {
			totalAlbumSize = DAOFactory.instance(getActivity()).getAlbumDao().getTotalAlbumSize();
			backupedSize = totalAlbumSize - DAOFactory.instance(getActivity()).getAlbumDao().getUnBackupedSize();
			computeCurrentProgress(0);
			int remainCount = DAOFactory.instance(getActivity()).getAlbumDao().getRemainCount();
			if (remainCount > 0) {
				albumLayer1.setVisibility(View.INVISIBLE);
				albumLayer2.setVisibility(View.VISIBLE);
				String formatStr = getActivity().getString(R.string.album_back_remain_str);
				resultDeteil2.setText(String.format(formatStr, remainCount));
			} else {
				albumLayer1.setVisibility(View.VISIBLE);
				albumLayer2.setVisibility(View.INVISIBLE);
				backupProgressPromit.setVisibility(View.VISIBLE);
				List<AlbumFileInfo> failureList = DAOFactory.instance(getActivity()).getAlbumDao().getFailedAlbumInfoList();
				adapter.resetDatas(failureList);
				String formatStr = getActivity().getString(R.string.album_backup_failure_promit);
				resultDeteil1.setText(String.format(formatStr, failureList.size()));
			}
		}

		private void handleBackupMadieStart(String madiePath) {

			int remainCount = DAOFactory.instance(getActivity()).getAlbumDao().getRemainCount();
			String formatStr = getActivity().getString(R.string.album_back_remain_str);
			resultDeteil2.setText(String.format(formatStr, remainCount));

			current_backup_item.setImageResource(R.mipmap.default_file_icon);
			int resourceId = R.mipmap.default_file_icon;
			File currentMadieFile = new File(madiePath);
			if (currentMadieFile.exists() && currentMadieFile.isFile()) {
				resourceId = getTypeImgeID(currentMadieFile.getName());
				if (resourceId == R.mipmap.empty_pic) {
					Bitmap tempBitmap = currentProcBitmap;
					currentProcBitmap = BitmapUtil.decodeSampledBitmapFromFile(madiePath, WIDTH, HEIGHT);
					if (currentProcBitmap != null) {
						current_backup_item.setImageBitmap(currentProcBitmap);
					} else {
						current_backup_item.setImageResource(resourceId);
					}
					if (tempBitmap != null && !tempBitmap.isRecycled()) {
						tempBitmap.recycle();
						tempBitmap = null;
					}
				} else {
					current_backup_item.setImageResource(resourceId);
				}
			}
		}

		private void handleBackupMadieProc(long itemProcedSize) {
			progress = computeCurrentProgress(itemProcedSize);
			backupProgress.setProgress(progress);
			backupProgress.setMax(100);
		}

		@Override
		protected void onHandlerBefore(Message msg, String errorCode) {
			super.onHandlerBefore(msg, errorCode);
		}

		@Override
		public Context getContext() {
			return getActivity();
		}

	};

	private ITCallback<UploadObject, FileInfoResponseV2> iCallback = new ITCallback<UploadObject, FileInfoResponseV2>() {

		public void onStart(UploadObject procData) {
			Message msg = handler.obtainMessage();
			msg.what = UiConstant.CALL_BACK_START;
			msg.obj = procData.getLoctPath();
			msg.sendToTarget();
		}

		public void onProgress(UploadObject procData, int progress, long proccedSize, long sizeByThis) {
			Message msg = handler.obtainMessage();
			msg.what = UiConstant.CALL_BACK_PROCESS;
			msg.obj = procData.getLoctPath();
			Bundle bundle = new Bundle();
			bundle.putLong(CURRENT_ITEM_PROCED_SIZE, proccedSize);
			msg.setData(bundle);
			msg.sendToTarget();
		}

		public void onSuccess(UploadObject procData, FileInfoResponseV2 response) {
			Message msg = handler.obtainMessage();
			msg.what = UiConstant.CALL_BACK_SUCCESS;
			msg.obj = procData.getLoctPath();
			msg.sendToTarget();
		}

		public void onFailure(UploadObject procData, Throwable t) {
			Message msg = handler.obtainMessage();
			msg.what = UiConstant.CALL_BACK_FIALURE;
			msg.obj = procData.getLoctPath();
			msg.sendToTarget();
		}
	};

	protected class TaskBroadcastReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (ReceiverConstent.ALBUM_TASK_NEW_INSTANCE_ACTION.equals(action)) {
				String filePath = intent.getStringExtra(ReceiverConstent.ALBUM_TASK_NEW_INSTANCE_DATA_1);
				Message msg = handler.obtainMessage();
				msg.what = UiConstant.CALL_BACK_PREPERD;
				msg.obj = filePath;
				msg.sendToTarget();
				AlbumUploadTaskManager.instance().registerCallback(iCallback);
			}
		}
	}

	class AlbumBackupFailureAdapter extends AbsTemplateAdapter<AlbumFileInfo> {

		public AlbumBackupFailureAdapter(List<AlbumFileInfo> translateList) {
			super(translateList);
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			ViewHolder holder = null;
			if (arg1 == null) {
				holder = new ViewHolder();
				arg1 = LayoutInflater.from(getActivity()).inflate(R.layout.album_backup_failure_item_view, arg2, false);
				holder.tvFileName = (TextView) arg1.findViewById(R.id.item_name_text);
				arg1.setTag(holder);
			} else {
				holder = (ViewHolder) arg1.getTag();
			}
			holder.tvFileName.setText(getItem(arg0).getFileName());
			return arg1;
		}

		class ViewHolder {
			TextView tvFileName;
		}

	}

}
